import { defineApis } from '@/utils/api'

//查询角色列表
const queryRoles = {
  url: "/role",
  method: "get",
};

//创建角色
const addRole = {
  url: "/role",
  method: "post",
};

//修改角色
const updateRole = {
  url: "/role",
  method: "put",
};

//删除角色
const removeRole = (id: number) => {
  return {
    url: `/role/${id}`,
    method: "DELETE",
  };
}

//查询某个角色的权限列表(只查询关联的权限)
const listRolePermission = (id: number) => {
  return {
    url: '/role/permission',
    params: {
      roleId: id
    },
  }
}

//查询指定角色的权限(分别查询内置权限和关联权限)
const listRoleSecurity = (roles: string[]) => {
  return {
    url: '/role/security',
    params: {
      roles
    },
  }
}

//为角色关联权限
const associateRolePermission = (roleId: number, permissionCode: string) => {
  return {
    url: '/role/permission',
    method: 'POST',
    params: {
      roleId,
      permissionCode
    },
  }
}

//移除角色的权限
const disassociateRolePermission = (roleId: number, permissionCode: string) => {
  return {
    url: '/role/permission',
    method: 'DELETE',
    params: {
      roleId,
      permissionCode
    },
  }
}

//为角色分配权限(新增和删除)
const setRolePermissions = {
  url: '/role/permissions',
  method: 'PUT'
}


export default defineApis('admin', {
  queryRoles,
  addRole,
  updateRole,
  removeRole,
  listRolePermission,
  listRoleSecurity,
  associateRolePermission,
  disassociateRolePermission,
  setRolePermissions
})